#pragma once 
#include<iostream>
#include"order.hpp"
#include"marketData.hpp"
#include "factor.hpp"
#include "position.hpp"
#include "utility.hpp"
#include "config.hpp"
#include <mutex>
#include<string>



class stock:tickPoint {
public:
	std::vector<marketData> rawMarketDataYesterday;
	std::vector<marketData> rawMarketDataToday;
	std::vector<config> myconfig;
	int code;
	int tick;
	int index;
	factorall myfactor;
	orderList myorder;
	status myPositionStatus;
	std::mutex mylock;
	int combi_no_now;

	stock(std::vector<config> config) {
		this->myconfig=config;
		this->code = config[0].code;
		this->myfactor = factorall();
		this->myPositionStatus.initialize(config);
		
	}

	void dataPreparation(std::string path,int today, std::vector<std::string> tradedays) {
		auto dateList = tradedays;
		std::string codeStr;
		std::string todayStr = std::to_string(today);
		if (code < 600000) {
			codeStr = std::to_string(code) + ".SZ";
		}
		else {
			codeStr = std::to_string(code) + ".SH";
		}
		if (rawMarketDataYesterday.size == 0) {
			for (int i = dateList.size() - 1; i >= 0; i--) {
				auto date = dateList[i];
				if (date < todayStr) {
					auto data = txtUtility::getDataFromTxt(path, codeStr, date);
					if (data.size() >= 1000) {
						this->rawMarketDataYesterday = data;
						this->myfactor.prepareYesterdayFeatureDataArray(data);
						break;
					}
				}
			}
		}
		if (rawMarketDataToday.size() == 0) {
			this->rawMarketDataToday= txtUtility::getDataFromTxt(path, codeStr, todayStr);
			this->myfactor.prepareTodayMarketDataArray(this->rawMarketDataToday);
		}
		if (this->myfactor.lastDataPrepared == true && this->myfactor.todayMarketDataPrePared == true) {
			this->myfactor.initializationSuccessful == true;
		}
	}

	void update(marketData md) {
		this->myfactor.update(md);
		this->tick = md.tick;
		this->myPositionStatus.update(md);
		this->index = updatetimeToIndex(md.tick);
		if (this->rawMarketDataToday.size() == 0 || updatetimeToIndex(this->rawMarketDataToday[this->rawMarketDataToday.size() - 1].tick) < this->index) {
			this->rawMarketDataToday.push_back(md);
		}
		
	}


	//std::lock_guard<std::mutex> lock(mylock);

};



